package com.jf.exam.controller.student;

import com.jf.exam.pojo.data.StudentDO;
import com.jf.exam.pojo.vo.ExamResultViewVO;
import com.jf.exam.pojo.vo.ExaminationResultVO;
import com.jf.exam.service.ExaminationResultService;
import com.jf.exam.utils.DataUtils;
import com.jf.exam.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/student/notes")
public class ExamResultController {
    @Autowired
    ExaminationResultService examinationResultService;

    @Value("#{properties['student.examinationResult.pageSize']}")
    private int pageSize;
    @Value("#{properties['student.examinationResult.navigatePages']}")
    private int navigatePages;

    @RequestMapping
    public String notes(HttpServletRequest request, Model model) throws Exception {
        return notes("1", request, model);
    }


    @RequestMapping("/{pn}")
    public String notes(@PathVariable String pn, HttpServletRequest request, Model model) throws Exception {
        StudentDO student = (StudentDO) request.getSession().getAttribute("student");
        int pageCode = DataUtils.getPageCode(pn);
        ExaminationResultVO vo = new ExaminationResultVO();
        vo.setFkStudent(student.getId());
        vo.setPageCode(pageCode);
        vo.setPageSize(pageSize);
        vo.setSize(navigatePages);
        PageBean<ExaminationResultVO> pageBean = examinationResultService.listExaminationResult(vo);
        model.addAttribute("pageBean", pageBean);
        return "student/examinationResult_list";
    }


    @RequestMapping("/view/{eid}")
    public String view(@PathVariable String eid, HttpServletRequest request, Model model) throws Exception {
        StudentDO student = (StudentDO) request.getSession().getAttribute("student");


        ExamResultViewVO viewVO = examinationResultService.getERViewById(eid,student.getId());

        model.addAttribute("view", viewVO);

        return "student/examinationResult_view";
    }

}
